package com.ruoyi.huanghefd.controller;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.huanghefd.domain.HighWorkApproveSheet;
import com.ruoyi.huanghefd.domain.WorkApproveSheet;
import com.ruoyi.huanghefd.service.WorkApproveSheetService;
import com.ruoyi.huanghefd.utils.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author gnplum
 * @Date 2024/12/12 16:28
 * @PackageName:com.ruoyi.huanghefd.controller
 * @ClassName: WorkApproveSheetController
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/huanghefd")
public class WorkApproveSheetController {
    private static final Logger log = LoggerFactory.getLogger(WorkApproveSheetController.class);

    @Resource
    private WorkApproveSheetService workApproveSheetService;

    /**
     * @param workApproveSheet
     * @return com.ruoyi.common.core.domain.AjaxResult
     * @Author gnplum
     * @Description 新增审批单
     * @Date 16:35 2024/12/12
     **/
    @PostMapping("/addWorkApproveSheet")
    public AjaxResult addWorkApproveSheet(@RequestBody WorkApproveSheet workApproveSheet) {
        log.info(">> 新增审批单-入参==" + JSON.toJSONString(workApproveSheet));
        AjaxResult ajax = workApproveSheetService.addWorkApproveSheet(workApproveSheet);
        log.info("<< 新增审批单-返回==" + ajax.toString());
        return ajax;
    }

    /**
     * @param asCode
     * @return com.ruoyi.common.core.domain.AjaxResult
     * @Author gnplum
     * @Description 删除审批单
     * @Date 16:35 2024/12/12
     **/
    @PostMapping(value = "/delWorkApproveSheet")
    public AjaxResult delWorkApproveSheet(@RequestParam(required = false, value = "asCode") String asCode) {
        log.info(">> 删除审批单-入参 asCode==" + asCode);
        if (asCode.isEmpty()) {
            return AjaxResult.success("请点选要删除的审批单");
        }
        AjaxResult ajax = workApproveSheetService.delWorkApproveSheet(asCode);
        log.info(">> 删除审批单-返回==" + ajax);
        return ajax;
//        WorkApproveSheet workApproveSheet = new WorkApproveSheet();
//        String json = JSON.toJSONString(workApproveSheet, JSONWriter.Feature.WriteNulls);
//        log.info("json = " + json);
//        return AjaxResult.success("成功");
    }

    /**
     * @param workApproveSheet
     * @return com.ruoyi.common.core.domain.AjaxResult
     * @Author gnplum
     * @Description 修改审批单
     * @Date 16:35 2024/12/12
     **/
    @PostMapping(value = "/uptWorkApproveSheet")
    public AjaxResult uptWorkApproveSheet(@RequestBody WorkApproveSheet workApproveSheet) {
        log.info(">> 修改审批单-入参 ==" + JSON.toJSONString(workApproveSheet));
        AjaxResult ajax = workApproveSheetService.uptWorkApproveSheet(workApproveSheet);
        log.info(">> 修改审批单-返回 ==" + ajax);
        return ajax;
    }

    /**
     * @param asCode
     * @param asDept
     * @param asState
     * @param userId
     * @param mailType
     * @param asType
     * @param pageNum
     * @param pageSize
     * @return com.ruoyi.huanghefd.utils.PageBean
     * @Author gnplum
     * @Description 查询审批单
     * @Date 16:35 2024/12/12
     **/
    @PostMapping(value = "/queryWorkApproveSheet")
    public PageBean queryWorkApproveSheet(@RequestParam(required = false, value = "asCode") String asCode, @RequestParam(required = false, value = "asDept") String asDept, @RequestParam(required = false, value = "asState") String asState, @RequestParam(required = false, value = "userId") String userId, @RequestParam(required = false, value = "mailType") String mailType, @RequestParam(required = false, value = "asType") String asType, @RequestParam(value = "pageNum") int pageNum, @RequestParam(value = "pageSize") int pageSize) {
        log.info(">> 查询审批单-入参==" + asCode + "," + asDept + "," + asState + "," + userId + "," + mailType + "," + asType);
        PageBean ajax = workApproveSheetService.queryWorkApproveSheetByPage(asCode, asDept, asState, userId, mailType, asType, pageNum, pageSize);//mailType 1-收件箱 2-发件箱 3-草稿箱
        log.info(">> 查询审批单-返回==" + ajax);
        return ajax;
    }

}
